<?php

public function txtIndex($act='',$token='')
	{
		if($act=='')
		{
			$this->load->vars('selector_action','main/txtIndex/');
			$data = array();
			$this->load->view('txt_index_select',$data);
		}
		else if($act=='model' && $token != '' && $this->input->post('do') == 'YES')
		{
			$group_model_id = $this->input->post('sl_group_model_id');
			$fl_model_code = $this->input->post('sl_model_specification_id');

			// GET MODEL SPEC ROW
			$model_specification = $this->db->select("a.id,a.model_name,a.model_code,b.group_model_name")
											->from('model_specification a')
											->where('a.model_code',$fl_model_code)
											->join('group_model b','b.id=a.group_model_id')
											->order_by('id','asc')
											->get()
											->row();
			// print_r($model_specification);
			// die();
			// GET SUB GROUP PART LIST								
			$sub_group_part_list = $this->db->select('a.id')
											->from('sub_group_part a')
											->where('model_id',$model_specification->id)
											->order_by('id','asc')
											->get()->result_object();
			// FLAT RATE TIME LIST
			// $flat_rate_time_index_list_parent = $this->db->select('a.operation_code')
			// 									  ->from('flat_rate_time a')
			// 									  ->where('a.fl_model_code',$fl_model_code)
			// 									  ->where('a.level','1')
			// 									  ->order_by('a.operation_code','asc')
			// 									  ->get()->result_object();



			// GET PART POSITION CODE BASED ON SUB GROUP PART LIST								
			$flat_rate_time_index_list = array();
												  
			$level2_where = array(); 
			$level2_where_str = '';
			// POPULATE WHERE
			foreach ($sub_group_part_list as $ch) 
			{
		  		$level2_where[] = $ch->id;
		    }									  

		    if(count($level2_where) > 0)
		    {
		    	$level2_where_str = "(sub_group_part_id='".implode("' OR sub_group_part_id='", $level2_where) ."')";

		    	$flat_rate_time_index_list = $this->db->select('a.sub_group_part_id,a.part_position_code as operation_code,a.part_name operation_description')
												  ->from('part_position_code a')
												  ->where($level2_where_str)
												  //->where('a.level','2')
												  ->order_by('a.part_name','asc')
												  ->get()->result_object();

		    }
		    foreach ($flat_rate_time_index_list as &$index) {
		    	$index->link = $index->operation_code . '/'. $fl_model_code . '/1/' . $index->sub_group_part_id;
		    }
		    // echo $this->db->last_query();
		    // die();
		    $this->load->vars('flat_rate_time_index_list',$flat_rate_time_index_list);
		   
			$this->load->vars('v_group_model_name',$model_specification->group_model_name);
			$this->load->vars('v_spec',$model_specification->model_name);
			$this->load->vars('model_code',$fl_model_code);
			$this->load->vars('model_specification',$model_specification);
			$this->load->view('txt_index_search');

		}
		else if($act == 'subGroupFlatRate' && $token != '')
		{


			$map = $this->grid_model->build_map_from_sub_group_part($token);
			// print_r($map);
			// die();
			$sub_group_part = $this->db->where('id',$token)->get('sub_group_part')->row();
			$group_part = $this->db->select('a.id,
											 a.group_part_name as group_name,
											 b.model_code,
											 a.group_part_code as group_code,
											 c.group_model_name,
											 b.model_name')
									->join('model_specification b','a.model_id = b.id','left')
									->join('group_model c','b.group_model_id = c.id','left')
									->where('a.id',$sub_group_part->group_part_id)
									->from('group_part a')
									->get()
									->row();
			$this->load->vars('sub_group_part',$sub_group_part);
			$this->load->vars('map',$map);
			$v_group_model_name = $group_part->group_model_name;
			$v_spec = $group_part->model_name;
			$v_group_code = $group_part->group_code;
			//echo($operation_code);
			
			//print_r($group_part);
			$this->load->vars('v_sub_group_name',$sub_group_part->sub_group_part_name);
			$this->load->vars('v_sub_group_code',$sub_group_part->sub_group_part_code);
			$this->load->vars('v_group_model_name',$v_group_model_name);
			$this->load->vars('v_spec',$v_spec);
			$this->load->vars('v_group_code',$v_group_code);
			$this->load->view('ilustration_index_sub_group_flat_rate');
		}
		 
	}